package com.example.order.config.feign;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @Author: 唐佳辉
 * @CreateTime： 2025-05-08-11:10
 * @Description: feign拦截器 目前是添加请求头
 * @Version：1.0
 */
@Configuration
public class FeignRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes attributes = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes());
        if (attributes != null) {
            HttpServletRequest request = attributes.getRequest();
            requestTemplate.header(HttpHeaders.AUTHORIZATION,  request.getHeader(HttpHeaders.AUTHORIZATION));
            requestTemplate.header("proxyHost", request.getHeader("proxyHost"));
            requestTemplate.header("test", "test");
        }
    }


}
